Add mqttstats: headless Commodity for Home Assistant telemetry - #22
Conversation
A standalone AmigaOS Commodity publishing Amiga system telemetry (uptime, chip/fast RAM free, CPU model) to a Home Assistant broker via mqtt.library, with full MQTT Discovery so sensors appear automatically. Configured entirely through Workbench ToolTypes (via amiga.lib's ArgArrayInit), runnable silently from WBStartup, with Commodities Exchange as its only control surface (Enable/Disable/Kill) - the telemetry piece of issue #6, scoped ahead of I2C sensor support which remains a follow-up. Adds the portable src/tools/ha_discovery.[ch] module (HA MQTT Discovery topic/payload builder, host-unit-tested) shared with mqttstats, and userdocs/mqttstats.md covering ToolTypes and Home Assistant setup. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QWq1CRLCQy9AaD9UtLRSM9
Without a .info icon, mqttstats couldn't actually be double-clicked or dropped into WBStartup: - a direct requirement from the issue this tool was built for. tools/mkicons.py (ported from AmiAuth's generator) produces a classic 4-colour, 2-bitplane DiskObject icon with a few common Tool Types pre-listed as edit-in-place comments (HOST, CLIENTID, INTERVAL, CX_PRIORITY). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QWq1CRLCQy9AaD9UtLRSM9
|
Added a Workbench icon (`icons/mqttstats.info`, via a new `tools/mkicons.py` ported from AmiAuth's generator) - without one, `mqttstats` couldn't actually be double-clicked or dropped into `WBStartup:`, which was a direct requirement. Ships alongside the binary in `make dist`; `userdocs/mqttstats.md` and `Installation.md` updated accordingly. |
… version sensors - Icon now lists every ToolType (not just four), all disabled/commented - matches every read_config() key so nothing is hidden from the icon. - Initial MQTT_Connect() failures now retry with capped exponential backoff (mco_AutoReconnect only covers post-connect drops, not a failed first attempt) - lets mqttstats launch from WBStartup ahead of the TCP/IP stack's own startup entry without just quitting once. - Added MQTT_CONNECT_REFUSED (-102) as a proper public constant in mqtt.library's <libraries/mqtt.h> (mqtt.doc updated, api-reference regenerated). mqttstats checks for it specifically: unlike a transient connect failure, a CONNACK refusal (bad credentials, rejected client id, ...) means retrying won't help, so it opens intuition.library itself and shows a one-off EasyRequest before quitting - mqtt.library itself stays UI-free, this is purely the caller's own choice. - Added Kickstart version and Workbench version telemetry sensors (exec.library's and workbench.library's own lib_Version/lib_Revision). Formatting them hit a confirmed m68k-amigaos-gcc -O2 miscompile (garbage upper bits when a UWORD struct field reaches sprintf's "%u" varargs); worked around with a dedicated noinline manual formatter - see format_bcd_version()'s own comment for the full story. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QWq1CRLCQy9AaD9UtLRSM9
|
Follow-up round addressing feedback:
Also found and worked around a real m68k-amigaos-gcc `-O2` miscompile hit while adding those two sensors (garbage upper bits when a `UWORD` struct field reaches `sprintf`'s `%u` varargs) - tracked separately in #23 since it could affect other code built at `-O2`, not just this file. All verified on-target under Copperline: retry/backoff timing, discovery+state publish for all 8 sensors now including the two new ones, and the corrected version values (confirmed against the test image's actual Kickstart ROM). |
TR_GETSYSTIME doesn't measure time since reset - it returns the same absolute, calendar-rooted system clock DateStamp() is built on (seconds since 1978-01-01, set from the battery-backed RTC at boot), just with sub-second precision. Reported as "uptime" it produced a nonsensical ~48-year value on any machine with a working clock - caught in real use. Switched to ReadEClock()'s free-running hardware tick counter, which genuinely resets to 0 at power-on and has no notion of calendar date at all, while remaining exactly as immune to the DateStamp() clock-jump hazard issue #8 documents. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QWq1CRLCQy9AaD9UtLRSM9
|
Fixed a real bug found by @sidick after checking a live sensor: uptime was reporting ~1,535,701,114s (~48.7 years). Root cause: `TR_GETSYSTIME` doesn't measure time since reset - it returns the same absolute, calendar-rooted system clock `DateStamp()` is built on (seconds since 1978-01-01, set from the battery-backed RTC at boot), just with sub-second precision. It was picked specifically because it's immune to issue #8's clock-jump hazard, but that reasoning was based on a wrong assumption about what it actually measures. Switched to `ReadEClock()`'s free-running hardware tick counter instead - genuinely resets to 0 at power-on, no notion of calendar date at all, and is exactly as immune to the clock-jump hazard the original code was trying to avoid. Verified on-target: uptime now reports a sane small value matching actual elapsed time. |
… it mid-word Exchange's list truncates nb_Descr on OS 3.1 well before the end, cutting "...to Home Assistant via MQTT" down to "...to Home Ass". Reordered so "Home Assistant" lands safely inside the observed ~37-character cutoff instead of running off the end of the string. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QWq1CRLCQy9AaD9UtLRSM9
|
Fixed the Exchange description truncation: reordered "Publishes Amiga telemetry to Home Assistant via MQTT" -> "Amiga telemetry to Home Assistant via MQTT" so "Home Assistant" lands safely inside the ~37-character cutoff Exchange applies on 3.1, instead of running right off the end into "...to Home Ass". |
Summary
mqttstatstool (src/amiga/mqttstats_main.c): a headless AmigaOS Commodity publishing Amiga telemetry (uptime, chip/fast RAM free, CPU model) to Home Assistant via MQTT Discovery, entirely configured through Workbench ToolTypes (amiga.lib'sArgArrayInit) and safe to drop intoWBStartup:- no window ever, Commodities Exchange (Enable/Disable/Kill) is its only control surface.src/tools/ha_discovery.[ch]module: builds HA MQTT Discovery topics/payloads, host-unit-tested (tests/test_ha_discovery.c).userdocs/mqttstats.mdadded (ToolTypes reference, Home Assistant setup, WBStartup instructions), wired intomkdocs.ymlnav andtools/docs2guide.pyformidge.guide.docs/ARCHITECTURE.mdupdated with the new file,Makefile'sdisttarget now shipsmqttstatsin the release archive.Test plan
make test- 276 passed, 0 failed (26 new checks forha_discovery)make lint- cleanmake m68k-docker- all 6 binaries (includingmqttstats) build warning-freemake guide+mkdocs build --strict- docs build cleanmosquitto_sub, and verified the missing-HOSTerror path returns cleanly with no window and no Shell/Startup-Sequence hang🤖 Generated with Claude Code
https://claude.ai/code/session_01QWq1CRLCQy9AaD9UtLRSM9